package pers.vic.practice.base.model;

import pers.vic.practice.base.constant.BaseConstant;
import pers.vic.practice.base.enums.UserType;
import pers.vic.practice.module.student.model.SStudent;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 描述:
 * @author Vic.xu
 * @date 2022-04-11 16:23
 */
public class Principal implements Serializable {

    private static final long serialVersionUID = 1L;

    private SStudent student;

    private Manager manager;

    private UserType userType;

    /**
     * 权限标识
     */
    private List<String> permissions;

    /**
     * 拥有的菜单
     */
    private List<String> urls;

    public static Principal buildStudent(SStudent student){
        Principal principal = new Principal(UserType.student);
        principal.setStudent(student);
        principal.setPermissions(BaseConstant.STUDENT_PERMISSIONS);
        principal.setUrls(BaseConstant.STUDENT_URLS);
        return principal;

    }

    public static Principal buildManager(Manager manager){
        Principal principal = new Principal(UserType.manager);
        principal.setManager(manager);
        principal.setPermissions(BaseConstant.MANAGER_PERMISSIONS);
        principal.setUrls(BaseConstant.MANAGER_URLS);
        return principal;

    }

    public Principal(){
        this.permissions = new ArrayList<>();
        this.urls = new ArrayList<>();
    }

    public Principal(UserType userType) {
        this();
        this.userType = userType;
    }

    public String getUserDesc(){
        String desc = userType == UserType.manager ? "管理员":"学生";
        desc +=":" +  (userType == UserType.manager ? manager.getName()  : student.getName());
        return desc;
    }

    public List<String> getUrls() {
        return urls;
    }

    public void setUrls(List<String> urls) {
        this.urls = urls;
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

    public List<String> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<String> permissions) {
        this.permissions = permissions;
    }

    public SStudent getStudent() {
        return student;
    }

    public void setStudent(SStudent student) {
        this.student = student;
    }

    public Manager getManager() {
        return manager;
    }

    public void setManager(Manager manager) {
        this.manager = manager;
    }
}
